package com.umfb.edu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageInfo;
import com.umfb.commons.exception.OperateException;
import com.umfb.constant.State;
import com.umfb.demo.entity.edu.Album;
import com.umfb.demo.service.edu.IAlbumService;
import com.umfb.edu.mapper.AlbumMapper;
import com.umfb.utils.IdWorker;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * Created by zcah on 18-7-19.
 */
@Service
public class AlbumServiceImpl implements IAlbumService {
    @Autowired
    private  AlbumMapper albumMapper;
    @Override
    public List<Album> findAlbumByColumnId( String columnId) {
        if(StringUtils.isBlank(columnId)){
            return null;
        }
        List<Album> albums = albumMapper.findAlbumByColumnIdAndState(columnId, State.UNDELETE.getStateNum());
        return albums;
    }

    @Override
    public String saveOrUpdate(Album album) throws OperateException {
        if(album==null||StringUtils.isBlank(album.getAlbumName())){
            throw new OperateException("参数缺失");
        }
        Date cur = new Date();
        album.setUpdateAt(cur);
        if(StringUtils.isBlank(album.getAlbumId())){
            album.setCreateUser("00000000000000000000000");
            album.setAlbumId(IdWorker.getIdWorker().nextId());
            album.setState(State.UNDELETE.getStateNum());
            album.setCreateAt(cur);
            albumMapper.insert(album);
        }else{
//            //gengxin
//            album.setOrganizationId(null);
//            album.setCreateUser(null);
//            albumMapper.updateByAlbumIdSelective(album);
        }
        return album.getAlbumId();
    }

    @Override
    public PageInfo<Album> findAlbumListByOrgIdAndColumnId(Integer pageNum, Integer pageSize, String organizationId, String columnId) {
        return null;
    }

    @Override
    public Album detailAlbum(String albumId) {

        Album album = albumMapper.selectByAlbumId(albumId);
        return album;
    }
}
